cmake_minimum_required(VERSION 3.10)
project(stock_kline)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置使用 UTF-8 编码
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

# 添加ImGui源文件
set(IMGUI_DIR "D:/GIT/vcpkg-master/buildtrees/imgui/src/v1.91.8-164364f825.clean/")

# 查找 vcpkg 工具链
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
    set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
        CACHE STRING "")
endif()

# 查找依赖库
find_package(imgui CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(glad CONFIG REQUIRED)


# 鼠标十字
add_library(mouse_pos SHARED src/mouse_pos.cpp)
target_compile_definitions(mouse_pos PRIVATE MOUSE_POS_EXPORTS)

# 构建时间线库
add_library(timeline_lib SHARED
    src/timeline.cpp
)
target_compile_definitions(timeline_lib PRIVATE TIMELINE_EXPORTS)


# 构建资金管理库
add_library(money_manager SHARED
    src/money_manager.cpp
)
target_compile_definitions(money_manager PRIVATE MONEY_MANAGER_EXPORTS)


# 构建持仓管理库
add_library(position_manager SHARED
    src/position_manager.cpp
)
target_compile_definitions(position_manager PRIVATE POSITION_MANAGER_EXPORTS)


# 构建K线库
add_library(kline_lib SHARED
    src/kline_lib.cpp
)
target_compile_definitions(kline_lib PRIVATE KLINE_EXPORTS)
target_include_directories(kline_lib PRIVATE
    ${IMGUI_DIR}
    ${IMGUI_DIR}/backends
)
target_link_libraries(kline_lib PRIVATE 
    imgui::imgui
    mouse_pos
) 
target_link_options(kline_lib PRIVATE "$<$<CONFIG:Debug>:/NODEFAULTLIB:MSVCRTD>")

# 绘制MACD图表
add_library(macd_chart SHARED
    src/macd_chart.cpp
)
target_compile_definitions(macd_chart PRIVATE MACD_CHART_EXPORTS)
target_include_directories(macd_chart PRIVATE
    ${IMGUI_DIR}
    ${IMGUI_DIR}/backends
)
target_link_libraries(macd_chart PRIVATE 
    imgui::imgui
    mouse_pos
)
target_link_options(macd_chart PRIVATE "$<$<CONFIG:Debug>:/NODEFAULTLIB:MSVCRTD>")

# 构建成交量图表库
add_library(volume_chart SHARED
    src/volume_chart.cpp
)
target_compile_definitions(volume_chart PRIVATE VOLUME_CHART_EXPORTS)
target_include_directories(volume_chart PRIVATE
    ${IMGUI_DIR}
    ${IMGUI_DIR}/backends
)
target_link_libraries(volume_chart PRIVATE 
    imgui::imgui
    mouse_pos
)

# KDJ
add_library(KDJ_chart SHARED
    src/KDJ_chart.cpp
)
target_compile_definitions(KDJ_chart PRIVATE KDJ_CHART_EXPORTS)
target_include_directories(KDJ_chart PRIVATE
    ${IMGUI_DIR}
    ${IMGUI_DIR}/backends
)
target_link_libraries(KDJ_chart PRIVATE 
    imgui::imgui
    mouse_pos
)
target_link_options(KDJ_chart PRIVATE "$<$<CONFIG:Debug>:/NODEFAULTLIB:MSVCRTD>")

# 所有的股票数据读取
add_library(stock_data_loader SHARED
    src/stock_data_loader.cpp
)
target_compile_definitions(stock_data_loader PRIVATE STOCK_DATA_LOADER_EXPORTS)

# 构建股票分析器
add_library(stock_analyzer SHARED
    src/stock_analyzer.cpp
)
target_compile_definitions(stock_analyzer PRIVATE STOCK_ANALYZER_EXPORTS)

# 构建股票分析器2
add_library(stock_analyzer_2 SHARED
    src/stock_analyzer_2.cpp
)
target_compile_definitions(stock_analyzer_2 PRIVATE stock_analyzer_2_EXPORTS)

# 构建赌徒模块
add_library(gambler SHARED
    src/gambler.cpp
)
target_compile_definitions(gambler PRIVATE GAMBLER_EXPORTS)


# 构建csv读取库
add_library(read_stock_data SHARED
    src/stock_data.cpp
)
target_compile_definitions(read_stock_data PRIVATE READ_STOCK_DATA_EXPORTS)

# # 股票买卖策略
# add_library(position_adjuster SHARED
#     src/position_adjuster.cpp
# )
# target_compile_definitions(position_adjuster PRIVATE POSITION_ADJUSTER_EXPORTS)



# 添加可执行文件
add_executable(${PROJECT_NAME} src/main.cpp)

set(VCPKG_imgui_backends_DIR ${IMGUI_DIR}"/backends")

# 添加后端源文件到可执行文件
target_sources(${PROJECT_NAME} PRIVATE
    ${VCPKG_imgui_backends_DIR}/imgui_impl_glfw.cpp
    ${VCPKG_imgui_backends_DIR}/imgui_impl_opengl3.cpp
)

# 链接依赖库
target_link_libraries(${PROJECT_NAME} PRIVATE 
    imgui::imgui
    glfw
    glad::glad
    read_stock_data
    timeline_lib
    money_manager
    position_manager
    stock_data_loader
    stock_analyzer
    stock_analyzer_2
    gambler
    kline_lib
    volume_chart
    KDJ_chart
    macd_chart
    mouse_pos
)
target_link_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:Debug>:/NODEFAULTLIB:MSVCRTD>")
target_include_directories(${PROJECT_NAME} PRIVATE "${IMGUI_DIR}/backends")
